package com.foton.logistic.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.foton.logistic.R;
import com.foton.logistic.util.image.fresco.FrescoUtils;
import com.foton.logistic.util.image.fresco.InstrumentedDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by wuhaocong on 2017/7/8.
 */

public class PictureAdapter extends BaseAdapter {
    private List<String> data;
    private int MAX_COUNT;
    private final Context mContext;
    private boolean isShowType;

    public PictureAdapter(Context context, ArrayList<String> mSelPhotos, int maxPhoto, boolean b) {
        this.mContext = context;
        this.data = mSelPhotos;
        this.MAX_COUNT = maxPhoto;
        this.isShowType = isShowType;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.base_adapter_picture, null);
            holder = new ViewHolder(convertView);

           /* holder.mRv_add = (RelativeLayout) convertView.findViewById(R.id.rl_add);
            holder.mImv_photo = (InstrumentedDraweeView) convertView.findViewById(R.id.imv);*/
//            holder.mImv_add = (ImageView) convertView.findViewById(R.id.imv_add);
//            holder.mTv_add = (TextView) convertView.findViewById(R.id.tv_add);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        FrescoUtils.displayImage(holder.imv,"file://" + data.get(position));
     /*   if (!isShowType) {
            if (position == data.size()) {
               *//* holder.mRv_add.setVisibility(View.VISIBLE);
                holder.mImv_photo.setVisibility(View.GONE);*//*
            } else {
               *//* holder.mRv_add.setVisibility(View.GONE);
                holder.mImv_photo.setVisibility(View.VISIBLE);
                FrescoUtils.displayImage(holder.mImv_photo, "file://" + data.get(position), 120,
                        120);*//*
            }
        } else {
            //FrescoUtils.displayImage(holder.mImv_photo, data.get(position));
        }*/
        return convertView;
    }

    /*static class ViewHolder {
        //        private TextView mTv_add;
//        private ImageView mImv_add;
        *//*private InstrumentedDraweeView mImv_photo;
        private RelativeLayout mRv_add;*//*
    }*/

    class ViewHolder {
        @InjectView(R.id.imv)
        InstrumentedDraweeView imv;
        @InjectView(R.id.picture_text)
        TextView pictureText;
        @InjectView(R.id.lin_add)
        LinearLayout linAdd;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
